<template>
  <div v-if="props.show" class="modal-overlay">
    <div class="modal-content">
      <h3>初始化知识库</h3>
      <div class="form-group">
        <label for="init-path">初始化地址：</label>
        <input 
          id="init-path" 
          v-model="path" 
          type="text" 
          placeholder="请输入初始化地址"
        />
      </div>
      <div class="modal-actions">
        <button class="cancel-btn" @click="handleClose">取消</button>
        <button 
          class="confirm-btn" 
          @click="handleInit"
          :disabled="!path.trim() || isLoading"
        >
          {{ isLoading ? '初始化中...' : '确认' }}
        </button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const props = defineProps({
  show: Boolean
});

const emit = defineEmits(['close', 'init']);

const path = ref('');
const isLoading = ref(false);

const handleClose = () => {
  path.value = '';
  emit('close');
};

const handleInit = async () => {
  if (!path.value.trim()) return;
  
  isLoading.value = true;
  emit('init', path.value.trim());
  isLoading.value = false;
  handleClose();
};
</script>

<style scoped>
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  padding: 24px;
  border-radius: 8px;
  width: 400px;
  max-width: 90%;
}

h3 {
  margin-top: 0;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
}

input {
  width: 100%;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.cancel-btn {
  padding: 8px 16px;
  border: 1px solid #ddd;
  background-color: white;
  border-radius: 4px;
  cursor: pointer;
}

.confirm-btn {
  padding: 8px 16px;
  border: none;
  background-color: #4CAF50;
  color: white;
  border-radius: 4px;
  cursor: pointer;
}

.confirm-btn:disabled {
  background-color: #cccccc;
  cursor: not-allowed;
}
</style>